/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions;



import javax.naming.InitialContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.entity.Usuario;
import com.ejb.UsuarioFachadaRemote;
import java.text.SimpleDateFormat;

/**
 *
 * @author Diego
 */
public class AltaAdminAction extends org.apache.struts.action.Action {

    private UsuarioFachadaRemote UsuarioFachadaBean;

    private static final String EXITO = "ExitoAltaAdmin";
    private AltaAdminForm miForm;

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        miForm = (AltaAdminForm)form;

        String Nick = miForm.getNick();
        String Nombre = miForm.getNombre();
        String Apellido = miForm.getApellido();
        String Pass = miForm.getPass();
        String Email = miForm.getEmail();
        String fnac = miForm.getfnac();


        // Llamada al Enterprise Bean
        UsuarioFachadaBean = (UsuarioFachadaRemote)new InitialContext().lookup("java:comp/env/UsuarioFachadaBean");

        Usuario us ;
        us= new Usuario();
        us.setId(Long.MIN_VALUE);
        us.setNick(Nick);
        us.setPass(Pass);
        us.setNombre(Nombre);
        us.setApellido(Apellido);
        us.setFecha_Nacimiento(new SimpleDateFormat("dd/MM/yyyy").parse(fnac));
        us.setEmail(Email);
        us.setEsAdministrador(true);
        UsuarioFachadaBean.persist(us);

        request.setAttribute("Nick", Nick);
        request.setAttribute("Nombre", Nombre);
        request.setAttribute("Apellido", Apellido);
        request.setAttribute("Pass", Pass);
        request.setAttribute("Email", Email);
        request.setAttribute("fnac",fnac);

        return mapping.findForward(EXITO);
    }
}
